package com.ruoyi.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.MesSordMapper;
import com.ruoyi.system.domain.MesSord;
import com.ruoyi.system.service.IMesSordService;

/**
 * 销售订单Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-06-04
 */
@Service
public class MesSordServiceImpl implements IMesSordService 
{
    @Autowired
    private MesSordMapper mesSordMapper;

    /**
     * 查询销售订单
     * 
     * @param id 销售订单主键
     * @return 销售订单
     */
    @Override
    public MesSord selectMesSordById(String id)
    {
        return mesSordMapper.selectMesSordById(id);
    }

    /**
     * 查询销售订单列表
     * 
     * @param mesSord 销售订单
     * @return 销售订单
     */
    @Override
    public List<MesSord> selectMesSordList(MesSord mesSord)
    {
        return mesSordMapper.selectMesSordList(mesSord);
    }

    /**
     * 新增销售订单
     * 
     * @param mesSord 销售订单
     * @return 结果
     */
    @Override
    public int insertMesSord(MesSord mesSord)
    {
        return mesSordMapper.insertMesSord(mesSord);
    }

    /**
     * 修改销售订单
     * 
     * @param mesSord 销售订单
     * @return 结果
     */
    @Override
    public int updateMesSord(MesSord mesSord)
    {
        return mesSordMapper.updateMesSord(mesSord);
    }

    /**
     * 批量删除销售订单
     * 
     * @param ids 需要删除的销售订单主键
     * @return 结果
     */
    @Override
    public int deleteMesSordByIds(String[] ids)
    {
        return mesSordMapper.deleteMesSordByIds(ids);
    }

    /**
     * 删除销售订单信息
     * 
     * @param id 销售订单主键
     * @return 结果
     */
    @Override
    public int deleteMesSordById(String id)
    {
        return mesSordMapper.deleteMesSordById(id);
    }

    @Override
    public boolean isSordIdUnique(MesSord mesSord, Boolean addOrUpdate)
    {
        int count = mesSordMapper.countBySordId(mesSord.getSordId());
        if(addOrUpdate) {
            return count == 0;
        }
        else {
            if(mesSord.getSordId().equals(mesSord.getOldSordId())){
                return count == 1;
            }
            else {
                return count == 0;
            }
        }
    }
}
